package com.example.waterorder.tools;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;

import java.util.Date;
import java.util.List;

public class FastJsonUtil {
    private static SerializeConfig serializeConfig = new SerializeConfig();

    static {
        serializeConfig.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
    }

    public static String toJsonString(Object object) {
        return JSON.toJSONString(object, serializeConfig, SerializerFeature.WriteNullStringAsEmpty);
    }

    public static <T> T fromJsonString(String jsonString, Class<T> clazz) {
        return JSON.parseObject(jsonString, clazz);
    }

    public static <T> List<T> fromJsonArray(String jsonArrayString, Class<T> clazz) {
        return JSON.parseArray(jsonArrayString, clazz);
    }
}
